O1.セル
●●●「表示形式」を[文字列]に指定したケ−ス。
Sub Macro1()
Range("B2").Select
Selection.NumberFormatLocal = "@"
End Sub
---------------------------------------------------------
△●●「配置」を[横:右詰め][縦:上詰め][折り返して表示][方向10度]に指定したケ−ス。
Sub Macro2()
With Selection
.HorizontalAlignment = xlRight
.VerticalAlignment = xlTop
.WrapText = True
.Orientation = 10
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With
Rows("2:2").RowHeight = 27.75
End Sub
・方向指定はExcel95にはなく、Excel95形式で保存すると角度ゼロ度になる。
---------------------------------------------------------
○●●「配置」で[セルを結合する]を指定し("A2:A5")を結合したケ−ス。
Sub Macro1b()
Range("A2:A5").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
End Sub
Excel97では結合したセルの途中に、行又は列の挿入・削除は不可であったがExcel2000
では出来ます。
---------------------------------------------------------
●●●「フォント」を[サイズ:12][スタイル:太字][色:ダイ]に指定したケ−ス。
Sub Macro3()
With Selection.Font
.Name = "MS Pゴシック"
.FontStyle = "太字"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 46
End With
End Sub
---------------------------------------------------------
△●●「罫線」でセルの回り及び斜めに罫線を付けたケ−ス。
Sub Macro4()
Range("A1").Select
With Selection.Borders(xlDiagonalDown)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub
・斜め罫線はExcel95にはなし、Excel95形式で保存すると斜め罫線は消える。
---------------------------------------------------------
●●●「パタ−ン」でセルの背景に青色を付けたケ−ス。
Sub Macro5()
Range("B2").Select
With Selection.Interior
.ColorIndex = 5
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
End Sub
■ カスタムマクロで上記の自動記録を使用する場合は、変化させた部分以外をカットすれば
ステ−トメントを少なく出来る。
PageTop
O2.行
PageTop
O2-1.高さ
●●●セルの高さを15.5に指定したケ−ス。
Sub Macro1()
Range("B2").Select
Selection.RowHeight = 15.5
End Sub
Top
O2-2.自動調整
●●●セルの高さを自動調整したケ−ス。
Sub Macro1()
Range("B2").Select
Selection.Rows.AutoFit
End Sub
Top
O2-3.表示しない
●●●下記は2行目を非表示にしたケ−ス
Sub Macro1()
Range("B2").Select
Selection.EntireRow.Hidden = True
End Sub
Top
O2-4.再表示
●●●上記で非表示にし2行目を再度表示に変えたケ−ス
Sub Macro1()
Range("B2").Select
Selection.EntireRow.Hidden = False
End Sub
■
Top
O3.列
PageTop
O3-1.幅
●●●セルの幅を10.38にしたケ−ス。
Sub Macro1()
Range("B2").Select
Selection.ColumnWidth = 10.38
End Sub
Top
O3-2.選択範囲に合わせる
●●●セルの幅をデ−タの幅に合わせたケ−ス。
Sub Macro1()
Range("B2").Select
Selection.Columns.AutoFit
End Sub
Top
O3-3.表示しない
●●●指定した列を非表示にする(本例はB列を非表示)。
Sub Macro1()
Range("B2").Select
Selection.EntireColumn.Hidden = True
End Sub
Top
O3-4.再表示
●●●本例は上記で非表示にしたB列を再表示する。
Sub Macro1()
Range("B2").Select
Selection.EntireColumn.Hidden = False
End Sub
Top
O3-5.標準の幅
●●●下記は、標準の幅ダイアログへ9を入れたケ−ス。
Sub Macro1()
ActiveSheet.StandardWidth = 9
End Sub
Top
O4.シ−ト
PageTop
O4-1.名前の変更
●●●シ−ト名("Sheet1")を"ABC"に変えたケ−ス。
Sub Macro1()
Sheets("Sheet1").Name = "ABC"
Range("E8").Select
End Sub
Top
O4-2.表示しない
●●●アクティブのシ−トを非表示にしたケ−ス。
Sub Macro1()
ActiveWindow.SelectedSheets.Visible = False
End Sub
■ Excel95では全部のシ−トを非表示に出来たが、Excel97以降は最後の1枚は非表示に出来ない。
Top
O4-3.再表示
●●●下記は、再表示ダイアログより("SheetA")を選択し表示に変えたケ−ス。
Sub Macro1()
Sheets("SheetA").Visible = True
End Sub
Top
O4-4.背景
●●●背景を付ける。本例は"C:\WINDOWS\トライアングル.bmp"を指定。
Sub Macro1()
ActiveSheet.SetBackgroundPicture Filename:="C:\WINDOWS\トライアングル.bmp"
End Sub
●●●背景の削除
Sub Macro2()
ActiveSheet.SetBackgroundPicture Filename:=""
End Sub
■ ワ−クシ−トの背景はそのまま保存される(大きなイメ−ジを背景にするとExcelブックの
容量が大きくなるので注意)
Top
O5.オ−トフォ−マット
●●●下記は、オ−トフォ−マットダイアログの表1を指定したケ−ス。
Sub Macro1()
Range("B5").Select
Selection.AutoFormat Format:=xlRangeAutoFormatLocalFormat1, Number:=True, _
Font:=True, Alignment:=True, Border:=True, Pattern:=True, Width:=True
End Sub
■ デ−タ範囲の1セルを指定すれば実行できるが、途中に空白行がある場合はその前で選択範囲
が終わってしまうのでカスタムマクロ作成ではデ−タ範囲全体を指定した方がよい。
PageTop
O6.条件付き書式
○●●条件付き書式ダイアログへ設定条件を入力。
Sub Macro1()
★ 自動記録されない
End Sub
PageTop
O7.スタイル
●●●セルの書式設定で設定されている内容を表示。
Sub Macro1()
With ActiveWorkbook.Styles("Normal")
.IncludeNumber = True
.IncludeFont = True
.IncludeAlignment = True
.IncludeBorder = True
.IncludePatterns = True
.IncludeProtection = True
End With
Selection.Style = "Normal"
End Sub
PageTop
O8.ふりがな
PageTop
O8-1.編集
○○●セル("B2")へ"木曽"と言う文字を入力しふりがな表示を指定したケ−ス。
Sub Macro1()
Range("B2").Select
ActiveCell.FormulaR1C1 = "木曽"
ActiveCell.Characters(1, 2).PhoneticCharacters = "キソ"
End Sub
■ ふりがなを表示に指定してないと表示されない。
Top
O8-2.設定
○●●ふりがなを表示する場所、フォントの指定。
Sub Macro1()
Range("B2").Select
Selection.Phonetics.CharacterType = xlKatakanaHalf
Selection.Phonetics.Alignment = xlPhoneticAlignDistributed
With Selection.Phonetics.Font
.Name = "MS Pゴシック"
.FontStyle = "標準"
.Size = 6
.Strikethrough = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
End Sub
Top
O8-3.表示/非表示
○●●表示
Sub Macro1()
Selection.Phonetics.Visible = True
End Sub
○●●非表示
Sub Macro1()
Selection.Phonetics.Visible = False
End Sub
■表示にした場合、自動的にセルの高さが変わるが、ユ−ザ−が高さを
設定してある時は変わらない。
Top